package net.jueb.httpFileServer;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpRequestDecoder;
import io.netty.handler.codec.http.HttpResponseEncoder;
import io.netty.handler.stream.ChunkedWriteHandler;

public class HttpFileServerInitializer extends ChannelInitializer<SocketChannel>{

	private  String rootDir;
	
	public HttpFileServerInitializer(String rootDir) {
		this.rootDir=rootDir;
	}
	
	@Override
	protected void initChannel(SocketChannel sc) throws Exception {
		sc.pipeline().addLast("http-decoder",new HttpRequestDecoder());
		sc.pipeline().addLast("http-aggregator",new HttpObjectAggregator(65536));
		sc.pipeline().addLast("http-encoder",new HttpResponseEncoder());
		//大文件传输处理
		sc.pipeline().addLast("http-chunked",new ChunkedWriteHandler());
		sc.pipeline().addLast(new HttpFileServerHandler(rootDir));
	}

}
